package com.topscomm.app.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.basic.exception.BusinessException;
import com.topscomm.basic.util.SQLAdapter;
import com.topscomm.cbo.model.TreeModel;
import com.topscomm.app.IAppController;
import com.topscomm.app.controller.auto.AppPageControllerAuto;
import com.topscomm.app.pojo.AppPageEntity;
import com.topscomm.app.service.impl.AppPageService;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

@RestController
@RequestMapping("app/appPage")
public class AppPageController extends AppPageControllerAuto implements IAppPageController {
	@Override
	protected String spellListSql(Map paraMap) {
		StringBufferProxy sql = new StringBufferProxy();		
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%'", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code='{0}'", value);
		}
		if (paraMap.containsKey("qry_where")) {
			String value = paraMap.get("qry_where").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and {0}", value);
		}		
		return sql.toString();
	}
	
	/**
	 * @description:
	 * @param paraMap
	 * @return
	 * @author: 张龙飞1
	 * @date: 2019年8月15日下午12:44:54
	 * @modify:
	 */
	@GetMapping(value = "/queryTreeList")
	public ResponseResult<Object> queryTreeList(@RequestParam(required = false) Map<String, Object> paraMap) {
		String sqlWhere = this.spellListSql(paraMap);
		sqlWhere += " order by code";
		List<AppPageEntity> listModule = this.service.queryByWhere(sqlWhere);
		List<Map<String, Object>> listNewModule = new ArrayList<Map<String, Object>>();
		for(AppPageEntity tabEntity : listModule) {
			listNewModule.add(tabEntity.convertToMap());
		}
		TreeModel treeModel = new TreeModel();
		List<TreeModel> deptTreeList = treeModel.buildTree(listNewModule, true, "页面树");
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("dataList", deptTreeList);
		return ResponseResult.ok(dataMap);
	}
	
	
	

	@GetMapping(value = "/list2")
	public ResponseResult<Object> list2(Map<String, Object> paraMap) {
		// TODO Auto-generated method stub
		return super.list(paraMap);
	}
	@GetMapping(value = "/list3")
	public ResponseResult<Object> list3(Map<String, Object> paraMap) {
		// TODO Auto-generated method stub
		return super.list(paraMap);
	}
}
